<?php

namespace app\common\model;

class AuthorModel extends CommonModel
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'author';

    /**
     * 初始化方法
     * {@inheritDoc}
     * @see CommonModel::initialize()
     */
    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * 添加或查询一个作者信息
     */
    public function get_or_add_info( $name )
    {
        $where = [
            "name" => $name
        ];

        $data = $this->muti_get_data_by_where( $where );
        if ( !$data ){
            $data = array(
                "name" => $name
            );

            $this->insert( $data );
            $data = $this->get_or_add_info( $name );
        }

        return $data;
    }
}
